Fitting PD-NEUT-CW LBCO-HRPT¶
This example shows how to refine the crystal structure parameters of La0.5Ba0.5CoO3 from neutron diffraction data in a constant wavelength experiment performed on HRPT diffractometer at PSI.
Import¶
import easydiffraction as ed
Job¶
Create a job — the main object to store all the information
job = ed.Job()
Model¶
Load a phase from CIF file
job.add_phase_from_file('data/lbco.cif')
print(job.phases)
Collection of 1 phases: ['lbco']
Show phase info in CIF format
phase = job.phases['lbco']
print(phase.cif)
data_lbco _cell_length_a 3.88 _cell_length_b 3.88 _cell_length_c 3.88 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'P m -3 m' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv La La 0.00000000 0.00000000 0.00000000 0.5 Biso 0.49 Ba Ba 0.00000000 0.00000000 0.00000000 0.5 Biso 0.49 Co Co 0.5 0.5 0.5 1.00000000 Biso 0.26 O O 0.00000000 0.5 0.5 1.00000000 Biso 1.4
Display the crystal structure of a given model
job.show_crystal_structure(id='lbco')
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol
Experiment¶
Load experimentally measured data from a file in XYE format
job.add_experiment_from_file('data/hrpt.xye')
Display the experimentally measured data
job.show_experiment_chart()
Define a point background
background_points = [(10.0, 170),
(165.0, 170)]
job.set_background(background_points)
Display the experiment chart after setting the background
job.show_experiment_chart()
Analysis¶
Display the analysis chart before setting initial parameter values
job.show_analysis_chart()
Create aliases for the two types of experimental parameters
pattern_params = job.pattern
experiment_params = job.parameters
Change the default value of the wavelength used in the experiment and display the analysis chart again
experiment_params.wavelength = 1.494
job.show_analysis_chart()
Change the scale and display the analysis chart again
phase.scale = 3
job.show_analysis_chart()
Change the default values of the peak profile related parameters and display the analysis chart again
experiment_params.resolution_u = 0.1
experiment_params.resolution_v = -0.1
experiment_params.resolution_w = 0.2
experiment_params.resolution_x = 0
experiment_params.resolution_y = 0
job.show_analysis_chart()
Select parameters to be refined in the first round
phase.scale.free = True
phase.cell.length_a.free = True
pattern_params.zero_shift.free = True
pattern_params.backgrounds[0][0].y.free = True
pattern_params.backgrounds[0][1].y.free = True
Print parameters to be refined (free parameters) before fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | length_a | 3.88 | 0.0 | Å |
| 2 | scale | 3.00 | 0.0 | |
| 3 | intensity | 170.00 | 0.0 | |
| 4 | intensity | 170.00 | 0.0 |
Start Least-Squares minimization to refine the selected parameters
job.fit()
Fitting successful Duration: 3.26 s Reduced chi: 2.39
Print the refined parameters after fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | length_a | 3.890878 | 0.000053 | Å |
| 2 | scale | 8.318452 | 0.035408 | |
| 3 | zero_shift | 0.621413 | 0.001515 | deg |
| 4 | intensity | 168.868476 | 0.738558 | |
| 5 | intensity | 182.109171 | 0.773572 |
Display the analysis chart after the first fitting
job.show_analysis_chart()
Select more parameters to be refined in the second round
experiment_params.resolution_u.free = True
experiment_params.resolution_v.free = True
experiment_params.resolution_w.free = True
experiment_params.resolution_y.free = True
Print free parameters before the second fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | length_a | 3.890878 | 0.000053 | Å |
| 2 | scale | 8.318452 | 0.035408 | |
| 3 | resolution_u | 0.100000 | 0.000000 | |
| 4 | resolution_v | -0.100000 | 0.000000 | |
| 5 | resolution_w | 0.200000 | 0.000000 | |
| 6 | resolution_y | 0.000000 | 0.000000 | |
| 7 | zero_shift | 0.621413 | 0.001515 | deg |
| 8 | intensity | 168.868476 | 0.738558 | |
| 9 | intensity | 182.109171 | 0.773572 |
Start second round of minimization
job.fit()
Fitting successful Duration: 3.12 s Reduced chi: 1.25
Print free parameters after the second fitting
job.print_free_parameters()
| names | values | errors | units | |
|---|---|---|---|---|
| 1 | length_a | 3.890879 | 0.000039 | Å |
| 2 | scale | 9.136625 | 0.034209 | |
| 3 | resolution_u | 0.081171 | 0.003132 | |
| 4 | resolution_v | -0.114045 | 0.006699 | |
| 5 | resolution_w | 0.119505 | 0.003265 | |
| 6 | resolution_y | 0.084460 | 0.002126 | |
| 7 | zero_shift | 0.622733 | 0.001053 | deg |
| 8 | intensity | 165.330718 | 0.550824 | |
| 9 | intensity | 176.928868 | 0.579114 |
Display the analysis chart after the second fitting
job.show_analysis_chart()